#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Domain;
using System.Web;
using Agresso.Interface.Layer.Service;
using System.Collections;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class SoftmarGradeAccountMappingForm : Form
    {
        GradeAccountMapping m_grade;
        UserControlSoftmarGradeAccountMapping m_parent;
        public SoftmarGradeAccountMappingForm(GradeAccountMapping grade, UserControlSoftmarGradeAccountMapping parent)
        {
            InitializeComponent();
            this.Text = "Softmar Charge Type Account Mapping";
            m_grade = grade;
            m_parent = parent;

            textBoxGrade.Text = grade.grade;
            textBoxAgrAccount.Text = grade.account;
            textBoxAgrAccountGRN.Text = grade.account_grn;
            //textBoxFullAddress.Text = supplierCustomer.full_address;
            //textBoxShortCode.Text = supplierCustomer.short_code;
            //textBoxCity.Text = supplierCustomer.city;
            //textBoxShortName.Text = supplierCustomer.short_name;
            //textBoxCountry.Text = supplierCustomer.country;
            //textBoxFullName.Text = supplierCustomer.full_name;
            //textBoxAccountCode.Text = supplierCustomer.account_code;
            //textBoxActive.Text = supplierCustomer.active == "1" ? "TRUE" : "FALSE";

            //textBoxAgrCustapar_id.Text = supplierCustomer.agr_cust_apar_id;
            //textBoxAgrCustapar_name.Text = supplierCustomer.agr_cust_apar_name;
            //textBoxAgrCustRelValue.Text = supplierCustomer.agr_cust_rel_value;
            //textBoxAgrSuppapar_id.Text = supplierCustomer.agr_supp_apar_id;
            //textBoxAgrSuppapar_name.Text = supplierCustomer.agr_supp_apar_name;
            //textBoxAgrSupprel_value.Text = supplierCustomer.agr_supp_rel_value;
        }
        public SoftmarGradeAccountMappingForm(string grade)
        {
            InitializeComponent();
            this.Text = "Softmar Charge Type Account Mapping";
            GradeAccountMappingService service = new GradeAccountMappingService();
            m_grade = service.GetGradeAccountMapping(grade);

            textBoxGrade.Text = m_grade.grade;
            textBoxAgrAccount.Text = m_grade.account;
            textBoxAgrAccountGRN.Text = m_grade.account_grn;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                UpdateSubject();
                this.Close();
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message, "Error Exception", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }

        private void UpdateSubject()
        {
            m_grade.account = textBoxAgrAccount.Text;
            m_grade.account_grn = textBoxAgrAccountGRN.Text;
            GradeAccountMappingService service = new GradeAccountMappingService();
            service.UpdateGradeAccountMapping(m_grade);
            if (m_parent != null)
                m_parent.UpdateSelectedItem(m_grade);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void textBoxAgrDescription_KeyDown(object objSender, KeyEventArgs objArgs)
        {
            buttonApply.Enabled = true;
        }

        private void buttonApply_Click(object sender, EventArgs e)
        {
            try
            {
                UpdateSubject();
                buttonApply.Enabled = false;
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message, "Error Exception", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }

        private void SoftmarVesselMappingForm_Load(object sender, EventArgs e)
        {
            textBoxAgrAccount.Focus();
            textBoxAgrAccount.SelectAll();
        }
    }
}